# coding:utf-8
# @Time    : 2021/12/3 15:53
# @Author  : Martin
import os
from time import sleep

from xlutils.copy import copy
import xlrd


def write_excel(file, datas: list):
    """
    用于商品范围模板的导入的修改
    # 模板只支持xls，考虑用xlrd
    :param file:
    :param datas:
    :return:
    """
    root_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    path = root_path + file
    book1 = xlrd.open_workbook(path)
    book2 = copy(book1)  # 拷贝一份原来的excel
    sheet = book2.get_sheet(0)  # 获取第一个sheet，book2现在的是xlutils里的方法，不是xlrd的
    row = 1
    for data in datas:
        col = 0
        for value in data:
            # xlutils:修改excel
            sheet.write(row, col, value)
            col += 1
        row += 1

    book2.save(path)



if __name__ == '__main__':
    write_excel('/excel_template/orderOptionalPackageScopeTemplate.xls', [(2, 2, 2, 2, 2)])
    # params = ["1_2_3", "4_5_6"]
    # for param in params:
    #     params[params.index(param)] = param.split('_')
    #
    # print(params)
    # book1 = xlrd.open_workbook('../excel_template/activityScopeTemplate.xls')
    # book2 = copy(book1)  # 拷贝一份原来的excel
    # sheet = book2.get_sheet(0)
    # sheet.write(1, 0, '*')
    # sheet.write(1, 1, '*')
    # sheet.write(1, 2, '*')
    # sheet.write(1, 3, '*')
    # book2.save('../excel_template/activityScopeTemplate.xls')
    pass
